package controllers

import (
	"gitee.com/lzqysoft/ims/models"
	"github.com/astaxie/beego"
	"encoding/json"
	"time"
)

type DeptProject struct {
	CommonController
}

func (c *DeptProject) URLMapping() {
	c.Mapping("GetAll", c.GetAll)
	c.Mapping("Update", c.Update)
}


// GetAll ...
// @Title get all DeptProject
// @Description get all  DeptProject
// @Param	body		body 	models.DeptProject	true		"body for SfCase content"
// @Success 201 {int} models.DeptProject
// @Failure 403 body is empty
// @router / [get]
func (c *DeptProject)GetAll()  {
	l, err := models.GetDeptProjects()
	if err != nil {
		beego.Debug(err)
		c.RetSuccess(ErrDatabase)
	}
	c.RetSuccess(l)
}

// Update ...
// @Title Update  DeptProject
// @Description Update   DeptProject
// @Param	body		body 	models.DeptProject	true		"body for SfCase content"
// @Success 201 {int} models.DeptProject
// @Failure 403 body is empty
// @router / [post]
func (c *DeptProject)Update () {
	user := c.User
	tdata, err := c.AesDecodeToByte(c.GetString("tdata"))
	if err != nil {
		beego.Debug(err)
		c.RetError(ErrToken)
	}
	var m models.DeptProject
	if err = json.Unmarshal(tdata, &m); err != nil {
		beego.Debug(err)
		c.RetError(ErrInputData)
	}
	m.Utime = time.Now()
	m.UpdaterId = user.Id
	m.Updater = user.Abbr
	if err = models.UpdateDeptProjectsById(&m); err != nil {
		beego.Debug(err)
		c.RetError(ErrDatabase)
	}
	c.RetSuccess(nil)

}